package com.wh.custom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wh.custom.pojo.EmployeeCustomer;
import com.wh.custom.service.IEmployeeCustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wh.custom.mapper.EmployeeCustomerMapper;
import com.wh.custom.dto.EmployeeCustomerDto;

import java.util.Arrays;
import java.util.List;

/**
 * 业务实现类：
 */
@Service
public class EmployeeCustomerServiceImpl implements IEmployeeCustomerService {

    @Autowired
    private EmployeeCustomerMapper employeeCustomerMapper;

    @Override
    public void add(EmployeeCustomer employeeCustomer){
        employeeCustomerMapper.insert(employeeCustomer);
    }

    @Override
    public void deleteById(Long id){
        employeeCustomerMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void patchDel(List<Long> ids){
        employeeCustomerMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateById(EmployeeCustomer employeeCustomer){
        employeeCustomerMapper.updateById(employeeCustomer);
    }

    @Override
    public EmployeeCustomer findOne(Long id){
        return employeeCustomerMapper.selectById(id);
    }

    @Override
    public List<EmployeeCustomer>findAll(){
        return employeeCustomerMapper.selectList(null);
    }

    @Override
    public IPage<EmployeeCustomer>findByPage(EmployeeCustomerDto employeeCustomerDto){
        //1.创建查询条件
        QueryWrapper<EmployeeCustomer> qw = new QueryWrapper<>();
        //qw.like("xxx",employeeCustomerDto.getXxx());
        //qw.or();
        //qw.like("xxx",employeeCustomerDto.getXxx());
        //2.组件分页数据
        IPage<EmployeeCustomer> page = new Page<>(employeeCustomerDto.getCurrentPage(), employeeCustomerDto.getPageSize());
        page.setRecords(employeeCustomerMapper.findByPage(page,qw));
        page.setTotal(employeeCustomerMapper.selectCount(qw));
        //3.返回
        return page;
    }
}
